<?php
/**
 * Auto Complete Customer Seach Interface
 * IT will return customer id and name
 *
 * @author Xavier VILAIN
 *
 */

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Connection;
use Fox\Common\Customer;
$terms = "%".Xview::instance()->val("term")."%";
$types = array(Customer::TYPE_BASIC,Customer::TYPE_PROSPECT);
$query = \Fox\Dao::infos(Customer::className())->handle()->createQueryBuilder();
$query->select("customerid as id","name1 as label")->from("customers","t");
$fragment = new Fox\Dao\SqlFragment("type IN (?) AND loekz = ? AND LOWER(name1) LIKE LOWER(?) "
,array($types,0,$terms),
array(Connection::PARAM_STR_ARRAY,Type::INTEGER,type::STRING));
$customers = $fragment->pushIn($query)->execute()->fetchAll(\PDO::FETCH_ASSOC);
echo json_encode($customers);